home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / newsgroups / misc.20020314-20021006 / 000258_fdc@columbia.edu_Fri Aug 2 10:11:23 EDT 2002.msg < prev    next >
Text File  |  2020-01-01  |  5KB  |  109 lines

  1. Article: 13574 of comp.protocols.kermit.misc
  2. Path: newsmaster.cc.columbia.edu!news.columbia.edu!news-not-for-mail
  3. From: fdc@columbia.edu (Frank da Cruz)
  4. Newsgroups: comp.protocols.kermit.misc
  5. Subject: Re: Renaming a file after receiving
  6. Date: 2 Aug 2002 10:11:09 -0400
  7. Organization: Columbia University
  8. Lines: 92
  9. Message-ID: <aie3tt$gch$1@watsol.cc.columbia.edu>
  10. References: <d49c50d5.0208011551.2aeed298@posting.google.com>
  11. NNTP-Posting-Host: watsol.cc.columbia.edu
  12. X-Trace: newsmaster.cc.columbia.edu 1028297471 25070 128.59.39.139 (2 Aug 2002 14:11:11 GMT)
  13. X-Complaints-To: postmaster@columbia.edu
  14. NNTP-Posting-Date: 2 Aug 2002 14:11:11 GMT
  15. Xref: newsmaster.cc.columbia.edu comp.protocols.kermit.misc:13574
  16.  
  17. In article <d49c50d5.0208011551.2aeed298@posting.google.com>,
  18. Luke Weese <hairyveggie@yahoo.com> wrote:
  19. : Hi.  So we all know, I am a newbie to C-Kermit scripting.  I have
  20. : written some scripts to dial in to a Wildcat BBS system, choose some
  21. : menu options, and receive a file using the Zmodem protocol (they
  22. : support Kermit protocol, but they highly recommend Zmodem because they
  23. : obviously havent read the Performance chapter in the Kermit manual,
  24. : judging by the 3.8% efficiency of the download).  All of this goes
  25. : through fine, but the only problem I had is that when using Zmodem,
  26. : the "as-name" argument to the receive command is apparently ignored. 
  27. :
  28. Because Zmodem is an external program.  In this scenario a file arrives
  29. and Zmodem receives it.  Kermit doesn't know the name of the file, so
  30. has no way to rename it.  This probably should be clarified in the
  31. documentation.
  32.  
  33. : I worked around this with some rather silly scripting involving
  34. : redirecting an "ls" command, parsing the filename and renaming, but I
  35. : was hoping someone could suggest a less clumsy way to rename the
  36. : downloaded file.  Here's the excerpt of my script:
  37. : -------------START----------------
  38. : mkdir tmpdir                        ; Make "tmpdir" to store this download
  39. : if fail goto mkdirfailed            ; Bail if permissions messed up
  40. : cd tmpdir                           ; Move into "tmpdir"
  41. : set take error on                   ; Set the error detection
  42. :
  43. This is the default anyway.
  44.  
  45. : set terminal autodownload off       ; Turn auto download off
  46. :                                     
  47. : set protocol zmodem rz {rz -a} {sz %s} {sz -a %s} rz {rz -a} ; Use Zmodem
  48. So far so good.  Btw, "set protocol zmodem" is sufficient -- the additional
  49. parameters are the default ones for Zmodem anyway.
  50.  
  51. : -------------DIALING, etc...------
  52. : receive hndyinvc.dat                          ; Download the file
  53. : If fail goto downloadfailure                  ; Error receiving file
  54. At this point you should have only newly downloaded files in your directory,
  55. since you just created and cd'd to it.
  56.  
  57. : .\%x := \Ffiles(*)                            ; Count the files in tmpdir
  58. : If = 1 \%x ls > ../dir.txt                    ; If only 1, list to parent dir
  59. : else goto oldfilesoutthere                    ; More than one file, bail
  60. This could happen if Zmodem received more than one file.
  61.  
  62. : cd ..                                         ; Go back to "hndmodem"
  63. : open read dir.txt                             ; Open list file
  64. : if fail goto nodirfile                        ; Bail if nonexistent
  65. : read \%o                                      ; Read first line, "total n"
  66. : if fail goto nodirfile                        ; Bail if nonexistent
  67. : read \%o                                      ; Read 2nd line with filename
  68. : if fail goto nodirfile                        ; Bail if nonexistent
  69. : .\%d := \Fsubstring(\%o,57)                   ; Get filename from pos 57 on
  70. : cd tmpdir                                     ; Go back to "tmpdir"
  71. : If exist \%d mv \%d ../hndyinvc.dat           ; If there, move back & rename
  72. : cd ..                                         ; Go back to "hndmodem"
  73. : rmdir tmpdir                                  ; Remove "tmpdir" for next time
  74. : If fail echo Could not remove "tmpdir" automatically. Please remove manually.
  75. : rm dir.txt                                    ; Remove "dir.txt"
  76. : If fail echo Could not remove "dir.txt" automatically. Pls remove manually.
  77. : ------------FINISH----------------
  78. : Please excuse any newbie mistakes in the coding, but feel free to
  79. : point them out.  Thanks in advance for any help.
  80. :
  81. \ffiles() not only returns the number of files that match its argument
  82. pattern, but also builds a list of files that you can cycle through with
  83. \fnextfile(), so you don't have to run an external directory-listing program
  84. or parse its output:
  85.  
  86.   if > \Ffiles(*) 1 stop 1 Multiple files received.
  87.   .filename := \fnextfile()
  88.   rename \m(filename) ../hndyinvc.dat
  89.   if fail stop 1 rename \m(filename) ../hndyinvc.dat failed.
  90.   cd ..
  91.   rmdir tmpdir
  92.   If fail stop 1 rmdir \v(dir)tmpdir failed.
  93.  
  94. Assigning \fnextfile() to a variable is necessary because every time you
  95. refer to \fnextfile() it returns the next filename.
  96.  
  97. - Frank
  98.